package com.ruoyi.web.controller.bom;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.bom.BomMaster;
import com.ruoyi.system.domain.bom.ZItemTree;
import com.ruoyi.system.domain.bom.vo.BomListArgs;
import com.ruoyi.system.domain.bom.vo.ItemList;
import com.ruoyi.system.domain.bom.vo.TemporaryTable;
import com.ruoyi.system.service.BomMasterService;
import com.ruoyi.system.service.ZItemTreeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@Controller
@RequestMapping("/bom")
public class BomController extends BaseController {

    @Autowired
    private BomMasterService bomMasterService;

    @Autowired
    private ZItemTreeService zItemTreeService;

    private String prefix = "bom";

    /**
     * 进入bom选单页面
     */
    @RequiresPermissions("bom:view")
    @GetMapping()
    public String bom(){
        return prefix + "/selectBom/selectBom";
    }

    /**
     * 打开BOM虚拟件查询页面
     */
    @RequiresPermissions("bom:view")
    @GetMapping("/openSelectBom")
    public String openSelectBom(){
        return prefix + "/selectBom/selectBom";
    }

    /**
     * 打开BOM虚拟件查询页面
     */
    @RequiresPermissions("bom:view")
    @GetMapping("/openItem")
    public String openItem(){
        return prefix + "/bom";
    }

    /**
     * 查询BOM所有虚拟件(根据条件)
     */
    @RequiresPermissions("bom:list")
    @PostMapping("/bomList")
    @ResponseBody
    public TableDataInfo selectBom(BomListArgs bomListArgs){
        startPage();
        List<BomMaster> list = bomMasterService.selectBomMasterList(bomListArgs);
        return getDataTable(list);
    }

    /**
     * 加载部门列表树
     */
    @RequiresPermissions("bom:list")
    @GetMapping("/itemTreeData")
    @ResponseBody
    public List<Ztree> itemTreeData()
    {
        List<Ztree> ztrees = zItemTreeService.selectItemTree(new ZItemTree());
        return ztrees;
    }

    /**
     * 获取所有物料(根据条件)
     */
    @RequiresPermissions("bom:list")
    @PostMapping("/queryTemporaryTable")
    @ResponseBody
    public TableDataInfo queryTemporaryTable()
    {
        startPage();
        List<TemporaryTable> list = bomMasterService.queryTemporaryTable();
        return getDataTable(list);
    }

    /**
     * 获取所有物料(根据条件)
     */
    @RequiresPermissions("bom:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ItemList item)
    {
        startPage();
        List<ItemList> list = bomMasterService.selectItemList(item);
        return getDataTable(list);
    }
}
